<%@ Page language="vb" CodeFile="addGarage.aspx.vb" Inherits="addGarage_aspx_vb" %>

<%
    rowNumber = 0
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        Over()
        strJS = ""
        strJS = strJS + "[""countryID"", ""<1""],"
        strJS = strJS + "[""garage"", ""==''""],"
        strJS = strJS + "[""street"", ""==''""],"
        strJS = strJS + "[""zipcode"", ""==''""],"
        strJS = strJS + "[""city"", ""==''""]"
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>ADD GARAGE<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addGarage.aspx?do=save' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Country:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='countryID' id='countryID'>")
        Response.Write("<option value=''> Select country  ")
        dbOpen()
        RecSet = Conn.Execute("Select countryID, country From tblCountry")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                countryID = RecSet.Fields("countryID").Value
                country = RecSet.Fields("country").Value
                Response.Write("<option value='" & countryID & "'> " & country & " ")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_countryID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td class='formBold'>Garage:</td><td align='right'><input type='text' name='garage' id='garage' size='40' maxlength='50'></td><td><div id='error_garage' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Street:</td><td align='right'><input type='text' name='street' id='street' size='40' maxlength='50'></td><td><div id='error_street' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Zipcode:</td><td align='right'><input type='text' name='zipcode' id='zipcode' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td><td><div id='error_zipcode' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'><input type='text' name='city' id='city' size='40' maxlength='50'></td><td><div id='error_city' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Areacode:</td><td align='right'><input type='text' name='areacode' id='areacode' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Telephone:</td><td align='right'><input type='text' name='telephone' id='telephone' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Fax:</td><td align='right'><input type='text' name='fax' id='fax' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Email:</td><td align='right'><input type='text' name='email' id='email' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Note:</td><td align='right'><input type='text' name='note' id='note' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>STATISTIC<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select Count(garageID) As garageCount From tblGarage")
        If Not RecSet.EOF Then 
            garageCount = RecSet.Fields("garageCount").Value
            Response.Write("<tr bgcolor='#eeeeee'><td>Number of garages saved:</td><td align='right'>" & garageCount & " st</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then 
        countryID = Request.Form("countryID")
        garage = Request.Form("garage")
        street = Request.Form("street")
        zipcode = Request.Form("zipcode")
        city = Request.Form("city")
        areacode = Request.Form("areaCode")
        telephone = Request.Form("telephone")
        fax = Request.Form("fax")
        email = Request.Form("email")
        note = Request.Form("note")
        userID = fragusLeasingUserID
        countryID = CLng(countryID)
        If Len(garage) > 0 Then 
            garage = Trim(garage)
            garage = Replace(garage, "'", "")
            garage = Replace(garage, """", "")
            garage = Replace(garage, "<", "")
            garage = Replace(garage, ">", "")
            garage = Replace(garage, "=", "")
        End IF
        If Len(street) > 0 Then 
            street = Trim(street)
            street = Replace(street, "'", "")
            street = Replace(street, """", "")
            street = Replace(street, "<", "")
            street = Replace(street, ">", "")
            street = Replace(street, "=", "")
        End IF
        If Len(zipcode) > 0 Then 
            zipcode = Trim(zipcode)
            zipcode = Replace(zipcode, "'", "")
            zipcode = Replace(zipcode, """", "")
            zipcode = Replace(zipcode, "<", "")
            zipcode = Replace(zipcode, ">", "")
            zipcode = Replace(zipcode, "=", "")
        End IF
        If Len(city) > 0 Then 
            city = Trim(city)
            city = Replace(city, "'", "")
            city = Replace(city, """", "")
            city = Replace(city, "<", "")
            city = Replace(city, ">", "")
            city = Replace(city, "=", "")
        End IF
        If Len(areacode) > 0 Then 
            areacode = Trim(areacode)
            areacode = Replace(areacode, "'", "")
            areacode = Replace(areacode, """", "")
            areacode = Replace(areacode, "<", "")
            areacode = Replace(areacode, ">", "")
            areacode = Replace(areacode, "=", "")
        End IF
        If Len(telephone) > 0 Then 
            telephone = Trim(telephone)
            telephone = Replace(telephone, "'", "")
            telephone = Replace(telephone, """", "")
            telephone = Replace(telephone, "<", "")
            telephone = Replace(telephone, ">", "")
            telephone = Replace(telephone, "=", "")
        End IF
        If Len(fax) > 0 Then 
            fax = Trim(fax)
            fax = Replace(fax, "'", "")
            fax = Replace(fax, """", "")
            fax = Replace(fax, "<", "")
            fax = Replace(fax, ">", "")
            fax = Replace(fax, "=", "")
        End IF
        If Len(email) > 0 Then 
            email = Trim(email)
            email = Replace(email, "'", "")
            email = Replace(email, """", "")
            email = Replace(email, "<", "")
            email = Replace(email, ">", "")
            email = Replace(email, "=", "")
        End IF
        If Len(note) > 0 Then 
            note = Trim(note)
            note = Replace(note, "'", "")
            note = Replace(note, """", "")
            note = Replace(note, "<", "")
            note = Replace(note, ">", "")
            note = Replace(note, "=", "")
        End IF
        dbOpen()
        Conn.Execute("Insert Into tblGarage (countryID, userID, garage, street, zipcode, city, areacode, telephone, fax, email, note) Values(" & countryID & "," & userID & ",'" & garage & "','" & street & "','" & zipcode & "','" & city & "','" & areacode & "','" & telephone & "','" & fax & "','" & email & "','" & note & "')")
        dbClose()
        Response.Redirect("addGarage.aspx?subDo=%20-%20SAVED")
    End IF
%>
